<template>
  <div class="title">公益行动</div>
  <div class="content">
    <div class="content-item" v-for="(item, index) in newsList" :key="index">
      <div class="left">
        <img :src="item.img" class="img" @click="getId(item)" />
      </div>
      <div class="right">
        <a href="javascript:;" class="titles" @click="getId(item)">{{
          item.title
        }}</a>
        <div class="contents">{{ item.content }}</div>
        <div class="look">
          <div class="num">阅读{{ item.num }}</div>
          <div class="time">{{ utils.day(item.pubtime) }}</div>
        </div>
      </div>
    </div>
  </div>
</template>

<script lang="ts" setup>
import { onMounted, ref } from "vue";
import { useRouter } from "vue-router";
import utils from "@/utils/utils";

const router = useRouter();

const newsList = ref<any>([]);

onMounted(() => {
  newsList.value = JSON.parse(window.localStorage.getItem("list") || "[]");
});

const getId = (item: any) => {
  router.push({
    path: "/active/contents",
    query: {
      id: item.id,
    },
  });
};
</script>

<style lang="less" scoped>
.title {
  padding: 10px;
  background-color: #eee;
  border-radius: 10px;
  font-size: 24px;
  font-weight: 600;
  margin-bottom: 20px;
}
.content {
  &-item {
    display: flex;
    padding: 10px;
    border-radius: 10px;
    background-color: #eee;
    margin-bottom: 10px;
    .left {
      width: 25%;
      height: 150px;
      .img {
        width: 100%;
        height: 100%;
      }
    }
    .right {
      width: calc(100% - 25%);
      padding: 10px 20px 0 20px;
      display: flex;
      flex-direction: column;
      justify-content: space-between;
      .titles {
        height: 20%;
        width: 80%;
        overflow: hidden;
        white-space: nowrap;
        text-overflow: ellipsis;
        padding: 5px 0;
        font-weight: 600;
      }
      .titles:hover {
        color: #c03030;
      }
      .contents {
        text-overflow: -o-ellipsis-lastline;
        overflow: hidden;
        text-overflow: ellipsis;
        display: -webkit-box;
        -webkit-line-clamp: 2;
        line-clamp: 2;
        -webkit-box-orient: vertical;
      }
      .look {
        display: flex;
        justify-content: space-between;
      }
    }
  }
}
</style>
